package com.zzl.bonds.ticket.controller;

import com.zzl.apidoc.annotation.ApidocController;
import com.zzl.apidoc.annotation.ApidocOperation;
import com.zzl.apidoc.annotation.ApidocParam;
import com.zzl.bonds.ticket.dto.BusinessContractAddDto;
import com.zzl.bonds.ticket.dto.BusinessContractUpdateDto;
import com.zzl.bonds.ticket.entity.BusinessContractEntity;
import com.zzl.bonds.ticket.service.BusinessContractService;
import com.zzl.general.common.apidoc.annotation.ApidocParamsPage;
import com.zzl.general.common.apidoc.annotation.ApidocResultKeyValR;
import com.zzl.general.common.apidoc.annotation.ApidocReturnPage;
import com.zzl.general.common.apidoc.annotation.ApidocReturnR;
import com.zzl.general.common.apidoc.constants.ResultTypeInR;
import com.zzl.general.common.ctrl.WebBaseCtrl;
import com.zzl.general.common.exception.SysException;
import com.zzl.general.common.utils.LogUtils;
import com.zzl.general.common.utils.PageUtils;
import com.zzl.general.common.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;
/**
 * 电子合同表
 *
 * @author gull
 * @date 2022-07-06 13:43:52
 */
@ApidocController("电子合同表")
@RestController
@SuppressWarnings("javadoc")
        @RequestMapping("ticket/businesscontract")
    @Slf4j
public class BusinessContractController extends WebBaseCtrl {
    @SuppressWarnings("all")
    @Autowired
    private BusinessContractService businessContractService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApidocOperation(description = "分页查询电子合同表数据", operationId = "ticket/businesscontract" + "/list")
    @ApidocReturnPage(genericTypeClass = BusinessContractEntity.class)
    public Result list(@ApidocParamsPage(name = "params") @RequestParam Map<String, Object> params) {
        PageUtils page = businessContractService.queryPage(params);
        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApidocOperation(description = "通过id获取电子合同表数据", operationId = "ticket/businesscontract" + "/info/{id}")
    @ApidocReturnR(otherkv = {
            @ApidocResultKeyValR(resultType = ResultTypeInR.TYPE_OBJECT, key = "businessContract", valueClass = BusinessContractEntity.class)
    })
    public Result info(@ApidocParam(description = "电子合同表id", name = "id", required = true) @PathVariable("id") String id) {
            BusinessContractEntity businessContract = businessContractService.getById(id);
        return Result.ok().put("data", businessContract);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApidocOperation(description = "保存电子合同表", operationId = "ticket/businesscontract" + "/save")
    @ApidocReturnR
    public Result save(@ApidocParam(description = "保存的电子合同表对象值", name = "{businessContract}", required = true) @RequestBody BusinessContractAddDto businessContract) {
        try {
                businessContractService.saveBusinessContract(businessContract, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApidocOperation(description = "修改电子合同表", operationId = "ticket/businesscontract" + "/update")
    @ApidocReturnR
    public Result update(@ApidocParam(description = "修改的电子合同表对象值", name = "businessContract", required = true) @RequestBody BusinessContractUpdateDto businessContract) {
        try {
                businessContractService.updateBusinessContractById(businessContract, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApidocOperation(description = "删除电子合同表", operationId = "ticket/businesscontract" + "/delete")
    @ApidocReturnR
    public Result delete(@ApidocParam(description = "删除的电子合同表对象id集合", name = "ids", required = true) @RequestBody String[] ids) {
            businessContractService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
